return FALSE;
}
+static gboolean
+gtk_builtin_icon_snapshot (GtkCssGadget *gadget,
+ GtkSnapshot *snapshot,
+ int x,
+ int y,
+ int width,
+ int height)
+{
+ GtkBuiltinIconPrivate *priv = gtk_builtin_icon_get_instance_private (GTK_BUILTIN_ICON (gadget));
+
+ gtk_snapshot_translate_2d (snapshot, x, y);
+ gtk_css_style_snapshot_icon (gtk_css_gadget_get_style (gadget),
+ snapshot,
+ width, height,
+ priv->image_type);
+ gtk_snapshot_translate_2d (snapshot, -x, -y);
+
+ return FALSE;
+}
+
static void
gtk_builtin_icon_style_changed (GtkCssGadget *gadget,
GtkCssStyleChange *change)
gadget_class->get_preferred_size = gtk_builtin_icon_get_preferred_size;
gadget_class->allocate = gtk_builtin_icon_allocate;
gadget_class->draw = gtk_builtin_icon_draw;
+ gadget_class->snapshot = gtk_builtin_icon_snapshot;
gadget_class->style_changed = gtk_builtin_icon_style_changed;
}
return _gtk_css_image_cross_fade_new (start, end, progress);
}
+static void
+gtk_css_image_real_snapshot (GtkCssImage *image,
+ GtkSnapshot *snapshot,
+ double width,
+ double height)
+{
+ cairo_t *cr;
+
+ cr = gtk_snapshot_append_cairo_node (snapshot,
+ &(graphene_rect_t)GRAPHENE_RECT_INIT (0, 0, width, height),
+ "Fallback<%s>", G_OBJECT_TYPE_NAME (image));
+ _gtk_css_image_draw (image, cr, width, height);
+ cairo_destroy (cr);
+}
+
static void
_gtk_css_image_class_init (GtkCssImageClass *klass)
{
klass->compute = gtk_css_image_real_compute;
klass->equal = gtk_css_image_real_equal;
klass->transition = gtk_css_image_real_transition;
+ klass->snapshot = gtk_css_image_real_snapshot;
}
static void
cairo_restore (cr);
}
+void
+gtk_css_image_snapshot (GtkCssImage *image,
+ GtkSnapshot *snapshot,
+ double width,
+ double height)
+{
+ GtkCssImageClass *klass;
+
+ g_return_if_fail (GTK_IS_CSS_IMAGE (image));
+ g_return_if_fail (snapshot != NULL);
+ g_return_if_fail (width > 0);
+ g_return_if_fail (height > 0);
+
+ klass = GTK_CSS_IMAGE_GET_CLASS (image);
+
+ klass->snapshot (image, snapshot, width, height);
+}
+
void
_gtk_css_image_print (GtkCssImage *image,
GString *string)
}
}
+void
+gtk_css_image_builtin_snapshot (GtkCssImage *image,
+ GtkSnapshot *snapshot,
+ double width,
+ double height,
+ GtkCssImageBuiltinType image_type)
+{
+ cairo_t *cr;
+
+ g_return_if_fail (GTK_IS_CSS_IMAGE (image));
+ g_return_if_fail (snapshot != NULL);
+ g_return_if_fail (width > 0);
+ g_return_if_fail (height > 0);
+
+ if (!GTK_IS_CSS_IMAGE_BUILTIN (image))
+ {
+ gtk_css_image_snapshot (image, snapshot, width, height);
+ return;
+ }
+
+ cr = gtk_snapshot_append_cairo_node (snapshot,
+ &(graphene_rect_t)GRAPHENE_RECT_INIT (0, 0, width, height),
+ "BuiltinImage<%d>", (int) image_type);
+ gtk_css_image_builtin_draw (image, cr, width, height, image_type);
+ cairo_destroy (cr);
+}
+
+
double width,
double height,
GtkCssImageBuiltinType image_type);
+void gtk_css_image_builtin_snapshot (GtkCssImage *image,
+ GtkSnapshot *snapshot,
+ double width,
+ double height,
+ GtkCssImageBuiltinType image_type);
G_END_DECLS
#include "gtk/gtkcssparserprivate.h"
#include "gtk/gtkcsstypesprivate.h"
+#include "gtk/gtksnapshotprivate.h"
G_BEGIN_DECLS
cairo_t *cr,
double width,
double height);
+ void (* snapshot) (GtkCssImage *image,
+ GtkSnapshot *snapshot,
+ double width,
+ double height);
/* parse CSS, return TRUE on success */
gboolean (* parse) (GtkCssImage *image,
GtkCssParser *parser);
cairo_t *cr,
double width,
double height);
+void gtk_css_image_snapshot (GtkCssImage *image,
+ GtkSnapshot *snapshot,
+ double width,
+ double height);
void _gtk_css_image_print (GtkCssImage *image,
GString *string);
style = gtk_css_node_get_style (gtk_css_gadget_get_node (GTK_CSS_GADGET (self)));
- gtk_css_style_snapshot_icon (style, snapshot, texture);
+ gtk_css_style_snapshot_icon_texture (style, snapshot, texture);
}
gboolean
cairo_set_matrix (cr, &saved_matrix);
}
+void
+gtk_css_style_snapshot_icon (GtkCssStyle *style,
+ GtkSnapshot *snapshot,
+ double width,
+ double height,
+ GtkCssImageBuiltinType builtin_type)
+{
+ const GtkCssValue *shadows, *transform;
+ cairo_matrix_t transform_matrix;
+ graphene_matrix_t matrix, other, saved_matrix;
+ GtkCssImage *image;
+
+ g_return_if_fail (GTK_IS_CSS_STYLE (style));
+ g_return_if_fail (snapshot != NULL);
+
+ image = _gtk_css_image_value_get_image (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_SOURCE));
+ if (image == NULL)
+ return;
+
+ shadows = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_SHADOW);
+ transform = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_TRANSFORM);
+
+ if (!_gtk_css_transform_value_get_matrix (transform, &transform_matrix))
+ return;
+
+ graphene_matrix_init_from_matrix (&saved_matrix, gtk_snapshot_get_transform (snapshot));
+
+ /* XXX: Implement -gtk-icon-transform-origin instead of hardcoding "50% 50%" here */
+ graphene_matrix_init_translate (&matrix, &(graphene_point3d_t)GRAPHENE_POINT3D_INIT(width / 2.0, height / 2.0, 0));
+ graphene_matrix_init_from_2d (&other, transform_matrix.xx, transform_matrix.yx,
+ transform_matrix.xy, transform_matrix.yy,
+ transform_matrix.x0, transform_matrix.y0);
+ graphene_matrix_multiply (&other, &matrix, &matrix);
+ graphene_matrix_init_translate (&other, &(graphene_point3d_t)GRAPHENE_POINT3D_INIT(- width / 2.0, - height / 2.0, 0));
+ graphene_matrix_multiply (&matrix, &other, &matrix);
+ gtk_snapshot_transform (snapshot, &matrix);
+
+ if (!_gtk_css_shadows_value_is_none (shadows))
+ {
+ g_warning ("Painting shadows not implemented for textures yet.");
+ }
+ gtk_css_image_builtin_snapshot (image, snapshot, width, height, builtin_type);
+
+ gtk_snapshot_set_transform (snapshot, &saved_matrix);
+}
+
static gboolean
get_surface_extents (cairo_surface_t *surface,
GdkRectangle *out_extents)
}
void
-gtk_css_style_snapshot_icon (GtkCssStyle *style,
- GtkSnapshot *snapshot,
- GskTexture *texture)
+gtk_css_style_snapshot_icon_texture (GtkCssStyle *style,
+ GtkSnapshot *snapshot,
+ GskTexture *texture)
{
const GtkCssValue *shadows, *transform;
cairo_matrix_t transform_matrix;
double width,
double height,
GtkCssImageBuiltinType builtin_type);
+void gtk_css_style_snapshot_icon (GtkCssStyle *style,
+ GtkSnapshot *snapshot,
+ double width,
+ double height,
+ GtkCssImageBuiltinType builtin_type);
void gtk_css_style_render_icon_surface (GtkCssStyle *style,
cairo_t *cr,
cairo_surface_t *surface,
double x,
double y);
-void gtk_css_style_snapshot_icon (GtkCssStyle *style,
+void gtk_css_style_snapshot_icon_texture (GtkCssStyle *style,
GtkSnapshot *snapshot,
GskTexture *texture);
texture = gsk_texture_new_for_pixbuf (pixbuf);
gtk_snapshot_translate_2d (snapshot, x, y);
- gtk_css_style_snapshot_icon (gtk_style_context_lookup_style (context),
- snapshot,
- texture);
+ gtk_css_style_snapshot_icon_texture (gtk_style_context_lookup_style (context),
+ snapshot,
+ texture);
gtk_snapshot_translate_2d (snapshot, -x, -y);
gsk_texture_unref (texture);
}